home *** CD-ROM | disk | FTP | other *** search
/ Oxygen Multimedia Graphics 22 / Oxygen Multimedia Graphics 22.iso / pc / System / OX22 / Internal_45_Waft.ls < prev    next >
Encoding:
Text File  |  2008-03-12  |  6.3 KB  |  179 lines

  1. property mySprite, getPDLError, myAnglePerFrame, myTurnFrames, myHShiftPerFrame, myShiftFrames, myTotalFrames, mySurfaceHeight, myInitialLoc, myRemainingFrames, myRotation, myTurnCounter, myDirection, myShiftCounter, myDoneFlag
  2.  
  3. on getBehaviorDescription me
  4.   return "WAFT" & RETURN & RETURN & "Makes a sprite rise up the screen like a bubble, rotating first one way then the other and vibrating horizontally as it rises. " & "The movement is somewhat random." & RETURN & RETURN & "By placing the surface below the starting height of the sprite, the same movement can be used to animate a falling leaf." & RETURN & RETURN & "The sprite will stop moving once it reaches the 'surface'. " & "At this moment it will send a custom WaftBehavior_Done message to all sprites. " & "You can use this message to trigger actions on other sprites, or to modify the current sprite. " & "See the example in the Notes for Developers in the script." & RETURN & RETURN & "If you want random movement that continues indefinitely, use the Random Movement and Rotation behavior instead." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "bitmap, Flash, vector shape" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Number of degrees to rotate in each frame" & RETURN & "* Maximum number of frames to rotate in each direction" & RETURN & "* Maximum horizontal pixel shift in each frame" & RETURN & "* Maximum number of frames to move in each direction" & RETURN & "* Number of frames taken to reach the surface" & RETURN & "* Height of the surface"
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Use with bitmap, Flash and vector shape members." & RETURN & RETURN & "Makes a sprite imitate the movement of a rising bubble or a falling leaf."
  9. end
  10.  
  11. on beginSprite me
  12.   Initialize(me)
  13. end
  14.  
  15. on prepareFrame me
  16.   if myRemainingFrames then
  17.     move(me)
  18.   else
  19.     if myDoneFlag then
  20.       SendCustomEvent(me)
  21.     end if
  22.   end if
  23. end
  24.  
  25. on Initialize me
  26.   mySprite = sprite(me.spriteNum)
  27.   myInitialLoc = mySprite.loc
  28.   myRemainingFrames = myTotalFrames
  29.   myDoneFlag = 1
  30.   myTurnCounter = myTurnFrames
  31.   myShiftCounter = myShiftFrames
  32. end
  33.  
  34. on move me
  35.   ChangeLevel(me)
  36.   Turn(me)
  37.   Shift(me)
  38. end
  39.  
  40. on ChangeLevel me
  41.   currentV = mySprite.locV
  42.   remainingV = currentV - mySurfaceHeight
  43.   deltaV = remainingV / myRemainingFrames
  44.   newV = currentV - deltaV
  45.   mySprite.locV = newV
  46.   myRemainingFrames = myRemainingFrames - 1
  47. end
  48.  
  49. on Turn me
  50.   if not myTurnCounter then
  51.     myRotation = not myRotation
  52.     myTurnCounter = random(myTurnFrames)
  53.   end if
  54.   myTurnCounter = myTurnCounter - 1
  55.   if myRotation then
  56.     newAngle = mySprite.rotation + myAnglePerFrame
  57.   else
  58.     newAngle = mySprite.rotation - myAnglePerFrame
  59.   end if
  60.   mySprite.rotation = newAngle
  61. end
  62.  
  63. on Shift me
  64.   if not myShiftCounter then
  65.     myDirection = not myDirection
  66.     myShiftCounter = random(myShiftFrames)
  67.   end if
  68.   myShiftCounter = myShiftCounter - 1
  69.   if myDirection then
  70.     mySprite.locH = mySprite.locH + myHShiftPerFrame
  71.   else
  72.     mySprite.locH = mySprite.locH - myHShiftPerFrame
  73.   end if
  74. end
  75.  
  76. on SendCustomEvent me
  77.   myDoneFlag = 0
  78.   sendAllSprites(#WaftBehavior_Done, me.spriteNum, me)
  79. end
  80.  
  81. on Waft_Reset me, propertyList
  82.   unchangedProps = [#totalFrames, #startLoc]
  83.   if not voidp(propertyList) then
  84.     if ilk(propertyList) = #propList then
  85.       i = propertyList.count()
  86.       repeat while i
  87.         theProp = propertyList.getPropAt(i)
  88.         theValue = propertyList[i]
  89.         case theProp of
  90.           #anglePerFrame:
  91.             case ilk(theValue) of
  92.               #integer, #float:
  93.                 myAnglePerFrame = theValue
  94.                 propertyList.deleteAt(i)
  95.             end case
  96.           #turnFrames:
  97.             case ilk(theValue) of
  98.               #integer, #float:
  99.                 myTurnFrames = abs(integer(theValue))
  100.                 propertyList.deleteAt(i)
  101.             end case
  102.           #hShiftPerFrame:
  103.             case ilk(theValue) of
  104.               #integer, #float:
  105.                 myHShiftPerFrame = abs(integer(theValue))
  106.                 propertyList.deleteAt(i)
  107.             end case
  108.           #shiftFrames:
  109.             case ilk(theValue) of
  110.               #integer, #float:
  111.                 myShiftFrames = abs(integer(theValue))
  112.                 propertyList.deleteAt(i)
  113.             end case
  114.           #totalFrames:
  115.             case ilk(theValue) of
  116.               #integer, #float:
  117.                 myRemainingFrames = abs(integer(theValue))
  118.                 propertyList.deleteAt(i)
  119.             end case
  120.           #surfaceHeight:
  121.             case ilk(theValue) of
  122.               #integer, #float:
  123.                 mySurfaceHeight = abs(integer(theValue))
  124.                 propertyList.deleteAt(i)
  125.             end case
  126.           #startLoc:
  127.             if ilk(theValue) = #point then
  128.               mySprite.loc = theValue
  129.               propertyList.deleteAt(i)
  130.             end if
  131.         end case
  132.         unchangedProps.deleteOne(theProp)
  133.         i = i - 1
  134.       end repeat
  135.       if propertyList.count() then
  136.         return propertyList
  137.       end if
  138.     else
  139.       return #invalidPropList
  140.     end if
  141.   end if
  142.   if unchangedProps.getPos(#startLoc) then
  143.     mySprite.loc = myInitialLoc
  144.   end if
  145.   if unchangedProps.getPos(#totalFrames) then
  146.     myRemainingFrames = myTotalFrames
  147.   end if
  148.   myDoneFlag = 1
  149. end
  150.  
  151. on Waft_GetReference me, theList
  152.   case ilk(theList) of
  153.     #list:
  154.       theList.append(me)
  155.     #propList:
  156.       theList.addProp(me.spriteNum, me)
  157.     otherwise:
  158.       return me
  159.   end case
  160.   return theList
  161. end
  162.  
  163. on isOKToAttach me, aSpriteType, aSpriteNum
  164.   case aSpriteType of
  165.     #graphic:
  166.       return getPos([#bitmap, #flash, #vectorShape], sprite(aSpriteNum).member.type) <> 0
  167.     #script:
  168.       return 0
  169.   end case
  170. end
  171.  
  172. on getPropertyDescriptionList me
  173.   return [#myAnglePerFrame: [#comment: "Angle to rotate in each frame", #format: #float, #default: 10], #myTurnFrames: [#comment: "Maximum frames to rotate in each direction", #format: #integer, #default: 10], #myHShiftPerFrame: [#comment: "Maximum horizontal shift in each frame", #format: #integer, #default: 10], #myShiftFrames: [#comment: "Maximum frames to shift in each direction", #format: #integer, #default: 10], #myTotalFrames: [#comment: "Number of frames to reach the surface", #format: #integer, #default: 60], #mySurfaceHeight: [#comment: "Height of surface (pixels from top of stage)", #format: #integer, #default: 0]]
  174. end
  175.  
  176. on PermittedMemberTypes me
  177.   return [#bitmap, #flash, #vectorShape]
  178. end
  179.